/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.app.skyview;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import space.app.common.Application;
import space.app.common.Server;

class SkyServer extends Server<TextureMessage> {



    public SkyServer(Application<TextureMessage> application) {
        super(application);
        
    }

    @Override
    public TextureMessage read(InputStream is) throws IOException {
        int b = is.read();
        if (b == -1) {
            throw new RuntimeException();
        }
        if (b == 255) {
            return null;
        }
        ByteArrayOutputStream bab = new ByteArrayOutputStream();
        for (int r = is.read(); r != -1; r = is.read()) {
            bab.write(r);
        }
        return new TextureMessage(TextureMessage.Kind.values()[b], bab.toByteArray());
    }
}
